/* clock em Hz */
#define F_CPU 16000000UL

#include <avr/io.h>
#include <util/delay.h>

void init_pwm(void) {

	TCCR1A = _BV(WGM11) |  _BV(COM1A1);
	TCCR1B = _BV(CS11) | _BV(WGM12) | _BV(WGM13); /* prescaler of 8, fast PWM */

        // 3456 is the servo center position
        OCR1A = 1500; /* 125 - 250 */
        ICR1 = 19999; // that evens out to 50hz

        DDRB = _BV(PB1); /* Set pin as output */
}


int main(void) {
       /* set PB0 to output */
       DDRC |= 1 << PC5;
	init_pwm();
	_delay_ms(1000);
	while(1) {
               /* LED on */
               PORTC |= 1 << PC5;
		OCR1A = 1100;
               _delay_ms(2000);

               /* LED off */
               PORTC &= ~(1 << PC5);
		OCR1A = 1900;
               _delay_ms(2000);
       }
	return 0;
}
